<template>
  <el-form :inline="true" :model="adddata" class="demo-form-inline">
    <el-form-item label="企业名称">
      <el-input
      v-model="adddata.enterpriseName"
        placeholder="请输入企业名称"
        clearable
      />
    </el-form-item>


    <el-form-item>
      <el-button type="danger" @click="gettableData()">搜索</el-button>
      <el-button type="primary" @click="gettableDatas()">新增</el-button>

    </el-form-item>
  </el-form>
  <el-table :data="tableData" style="width: 100%">
    <el-table-column prop="enterpriseName" label="企业名称" />
    <el-table-column prop="corporateLogo" label="图片">
      <template #default="scope">
        <img :src="scope.row.corporateLogo" alt="" style="width: 50px; height: 50px">
      </template>
    </el-table-column>
    <el-table-column prop="detailedAddress" label=" 企业详细地址" />
    <el-table-column prop="enterprisePhone" label="企业联系方式" />
    <el-table-column prop="defunctEnterprise" label="是否停用" >
      <template #default="scope">
        <el-text v-if="scope.row.defunctEnterprise==1">是</el-text>
        <el-text v-else>否</el-text>
      </template>
    </el-table-column>
    <el-table-column prop="superintendent" label="可查看人员" />
  </el-table>
   <!-- 分页 -->
   <div>
    <el-pagination
      v-model:current-page="adddata.pageIndex"
      v-model:page-size="adddata.pageSize"
      :page-sizes="[3, 5, 8, 10]"
      :background="true"
      layout="total, sizes, prev, pager, next, jumper"
      :total="adddata.totalCount"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script lang="ts" setup>
import axios from 'axios';
import { ref, reactive, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { useRoute, useRouter } from 'vue-router'

const apiUrl = import.meta.env.VITE_APP_API_URL;
const apiBedinUrl = import.meta.env.VITE_APPRead_API_URL;

const route = useRoute()
const router = useRouter()
const adddata = reactive({
  enterpriseName:'',
  pageIndex: 1,
  pageSize: 3,
  totalCount: 0,
  pageCount: 0,
})
const tableData = ref([])
const gettableData = () => {
  axios.post(' http://localhost:5039/api/Enterprise/ShowEnterprice', {
    enterpriseName: adddata.enterpriseName,
    pageIndex: adddata.pageIndex,
    pageSize: adddata.pageSize
  }).then(res => {
    tableData.value = res.data.data.list
    adddata.pageCount = res.data.data.pageCount;
    adddata.totalCount = res.data.data.totalCount;
  })
}
//分页
const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`)
  adddata.pageSize=val
  gettableData()
}
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`)
  adddata.pageIndex=val
  gettableData()
}
const gettableDatas = () => {
  router.push({
    path: '/EnterpriseAdd'
  })
}
onMounted(() => {
  gettableData()
})


</script>
